local Lang = require("common.Lang")
local Msg = require("core.Msg")
local ItemDefine = require("bag.ItemDefine")
local Equip =require("bag.Equip")
local Item2StringLogic = require("common.Item2StringLogic")

TYPE_ACTION_ON_SHOW_ITEM = 1		--展示道具
TYPE_ACTION_ON_JUMP_PATH = 2		--跳转
TYPE_ACTION_ON_ROLENAME = 3			--人名
TYPE_ACTION_ON_TALISMAN = 4			--法宝
TYPE_ACTION_ON_OPEN_TALISMAN = 5	--祭练
TYPE_ACTION_ON_MARKET_AD = 6		--我要购买
TYPE_ACTION_ON_FAMILY_APPLY = 7		--我要加入
TYPE_ACTION_ON_COPY_MATCH = 8		--我要匹配
TYPE_HELP_ME = 9					--前往救助
TYPE_JUBAO = 10						--我要举报
TYPE_OPEN_PANEL = 11				--打开面板
TYPE_ACTION_ON_SHOW_HUNTLIFE = 12	--猎命
TYPE_ACTION_SHOW_PET = 19			--宠物炫耀
TYPE_ACTION_SHOW_TALISMAN = 20		--坐骑炫耀
TYPE_ACTION_SHOW_WING = 21			--翅膀炫耀

local colorTable = {
	"#FFFFFF",			    --白色
	"#00EC1C",				--绿色
	"#1FABE1",				--蓝色
	"#DD61E2",				--紫色
	"#EB7B29",				--橙色
	"#FF1515",				--红色
	"#F1FF0A",				--金色
}
function fontAFlag(data,content)
	return "<a href=\'event:" .. data .."\'>" .. content .. "</a>"
end

function fontAFlagU(data,content)
	return "<u><a href=\'event:" .. data .."\'>" .. content .. "</a></u>"
end

function font(content, color, size)
  if type(color) == "number" then
	color = colorTable[color]
  end
  color = color or colorTable[1]
  if size then
	return "<font color='" .. color .. "' size='" .. size .. "'>" .. content .. "</font>"
  else
	return "<font color='" .. color .. "'>" .. content .. "</font>"
  end
end

function fontName(name,uuid,color)
	if type(color) == "number" then
		color = colorTable[color]
	end
	color = color or "#56E3F7"
	local data = TYPE_ACTION_ON_ROLENAME .. "|".. name .. "|" .. (uuid or "")
	name = "【" .. name .. "】"
	local content = font(name,color)--#facca7
	return fontAFlag(data,content)
end

function fontNameKuo(name,uuid)
	local data = TYPE_ACTION_ON_ROLENAME .. "|".. name .. "|" .. (uuid or "")
	local content = font("【" .. name .. "】","#56E3F7")--#facca7
	return fontAFlag(data,content)
end

function fontItem(grid, name)
	local data = TYPE_ACTION_ON_SHOW_ITEM .."|"..Item2StringLogic.fontItem(grid, name)
	local itemColor = ItemDefine.getValue(grid.id,"color")
	if ItemDefine.isEquip(grid.id) then
		itemColor = Equip.getColor(grid.data.equip.quality)
	end
	local itemName = name or "【<u>" .. ItemDefine.getValue(grid.id,"name") .. "</u>】"
	local content = font(itemName, itemColor)
	if 1 < grid.cnt then
		content = content .. font("x" .. grid.cnt, 1)
	end
	return fontAFlag(data, content)
end

function fontItemNoCnt(grid, name)
	local data = TYPE_ACTION_ON_SHOW_ITEM .."|"..Item2StringLogic.fontItem(grid, name)
	local itemColor = ItemDefine.getValue(grid.id,"color")
	if ItemDefine.isEquip(grid.id) then
		itemColor = Equip.getColor(grid.data.equip.quality)
	end
	local itemName = name or "【<u>" .. ItemDefine.getValue(grid.id,"name") .. "</u>】"
	local content = font(itemName, itemColor)
	return fontAFlag(data, content)
end


function fontItemId(id, cnt, color)
	local name = "【" .. ItemDefine.getValue(id,"name") .. "】"
	local content = font(name, color or ItemDefine.getValue(id,"color"))
	if 1 < cnt then
		content = content .. font("x" .. cnt, 1)
	end
	return content
end

-- 没有颜色
function fontItemId2(id, cnt)
	local name = "【" .. ItemDefine.getValue(id,"name") .. "】"
	local content = name
	if 1 < cnt then
		content = content .. "x" .. cnt
	end
	return content
end

-- 一直显示数量
function fontItemId3(id, cnt, color)
	local name = "【" .. ItemDefine.getValue(id,"name") .. "】"
	local content = font(name, color or ItemDefine.getValue(id,"color"))
	content = content .. font("x" .. cnt, 1)
	return content
end

function fontBindYuanbao(n)
	return font(n .. "绑定元宝", 4)
end

function fontYinliang(n)
	return font(n .. "银两", 1)
end

function fontYuanbao(n)
	return font(n .. "元宝", 6)
end

function fontTalisman(id)
	local conf = TalismanExcel.illusion[id]
	
	if not conf then
		return ""
	end
	
	local data = TYPE_ACTION_ON_TALISMAN .. "|".. id 
	local content = font("【" .. conf.name .. "】","#ffdd55")
	return fontAFlag(data,content)
end

function fontOpenTalisman()
	local data = TYPE_ACTION_ON_OPEN_TALISMAN
	local content = font(Lang.TALISMAN_PANEL_TIP,"#00FF00") 
	return fontAFlag(data,content) 
end

function fontNpcLink(npcID, npcName)
	if not npcID then return "" end
	
	local conf = ExcelNpcConf.npc[npcID]
	if not conf then return "" end
	
	return "<a href='event:" .. TYPE_ACTION_ON_JUMP_PATH .. "|" .. conf.mapID .. "," .. conf.mapX .. "," .. conf.mapY .. "," .. npcID .. ",1" .. "'><u>" .. "<font color='#00ff00'>" .. (npcName or conf.name) .. "</font>" .. "</u></a>"
end

function fontMapPoint()--mapID, x, y, content)
	return ""
end

function fontOpenPanelLink(panelID, content)
	return "<a href='event:" .. TYPE_ACTION_ON_JUMP_PATH .. "|" .. "open" .. "," .. panelID .. "'><u>"  .. "<font color='#00ff00'>" .. content .. "</font>" .. "</u></a>"
end

function fontHuntLifeId(id)
	local cf = HuntLifeExcel.config[id]
	if not cf then
		return ""
	end

	local msgRet = Msg.gc.GC_HUNTLIFE_BAG_CHANGE	
	HuntLifeLogic.fontNode(nil, msgRet.symbol, id)
	local data = TYPE_ACTION_ON_SHOW_HUNTLIFE .."|"..Item2StringLogic.tb2str(msgRet.symbol)
	
	
	local itemColor = cf.color
	local itemName = "【<u>" .. cf.name .. "</u>】"
	local content = font(itemName, itemColor)
	
	--print(content, data)
	return fontAFlag(data, content)	
end
